'''
“乐行人生”交通工具意外伤害保险
'''
import sys

sys.path.append('../')
from common.config import *
from db.mysql import MysqlClient
from itertools import product
from common.helper import Helper
from urllib.parse import urlencode
import requests
import json


class Spider(object):
    def __init__(self):
        self.mysql = MysqlClient()
        self.name = "“乐行人生”交通工具意外伤害保险"

    # 生成产品数据
    def genProductInfo(self):
        plan = {

            "planA": {

                "乘坐客运民航班机": "40w",
                "乘坐非营运机动车": "3w",
                "乘坐客运机动车": "3w",
                "乘坐客运轨道交通车辆": "20w",
                "乘坐客运轮船": "20w",
            },
            "planB": {

                "乘坐客运民航班机": "80w",
                "乘坐非营运机动车": "6w",
                "乘坐客运机动车": "6w",
                "乘坐客运轨道交通车辆": "40w",
                "乘坐客运轮船": "40w",
            },
            "planC": {

                "乘坐客运民航班机": "120w",
                "乘坐非营运机动车": "9w",
                "乘坐客运机动车": "9w",
                "乘坐客运轨道交通车辆": "60w",
                "乘坐客运轮船": "60w",
            },
            "planD": {

                "乘坐客运民航班机": "160w",
                "乘坐非营运机动车": "12w",
                "乘坐客运机动车": "12w",
                "乘坐客运轨道交通车辆": "80w",
                "乘坐客运轮船": "80w",
            },
            "planE": {

                "乘坐客运民航班机": "200w",
                "乘坐非营运机动车": "15w",
                "乘坐客运机动车": "15w",
                "乘坐客运轨道交通车辆": "100w",
                "乘坐客运轮船": "100w",
            },

        }

        price = 0

        expire = "1"

        for v in plan.values():
            price += 35

            expire = 1

            value = "'" + json.dumps( v ,ensure_ascii=False) + "'"

            self.mysql.cursor.execute(

                'INSERT INTO `“乐行人生”交通工具意外伤害保险`(`plan`,`expire`,`price`)VALUES({0},"{1}","{2}")'.format( value,str(expire),Helper.decimalParse(price))


            )
            self.mysql._conn.commit()



if __name__ == '__main__':
    s = Spider()

    s.genProductInfo()
